using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Design;

namespace Host
{
    public class NewFormRootDesigner : ComponentDesigner, IRootDesigner, IToolboxUser
    {
        NewFormControl _rootView;

        #region Implementation of IRootDesigner
        public object GetView(System.ComponentModel.Design.ViewTechnology technology)
        {
            _rootView = new NewFormControl(this);
            return _rootView;
        }
        public System.ComponentModel.Design.ViewTechnology[] SupportedTechnologies
        {
            get
            {
                return new ViewTechnology[] { ViewTechnology.Default };
            }
        }
        #endregion

        #region Implementation of IToolboxUser
        public void ToolPicked(System.Drawing.Design.ToolboxItem tool)
        {
            _rootView.InvokeToolboxItem(tool);
        }

        public bool GetToolSupported(System.Drawing.Design.ToolboxItem tool)
        {
            return true;
        }
        #endregion

        public new object GetService(Type type)
        {
            return base.GetService(type);
        }

        public class NewFormControl : Form
        {
            private NewFormRootDesigner _rootDesigner;

            public NewFormControl(NewFormRootDesigner rootDesigner)
            {
                _rootDesigner = rootDesigner;
                this.FormBorderStyle = FormBorderStyle.None;
                this.Size = new System.Drawing.Size(1024, 768);
            }

            public IDesignerHost DesignerHost
            {
                get
                {
                    return (IDesignerHost)_rootDesigner.GetService(typeof(IDesignerHost));
                }
            }

            public IToolboxService ToolboxService
            {
                get
                {
                    return (IToolboxService)_rootDesigner.GetService(typeof(IToolboxService));
                }
            }

            public void InvokeToolboxItem(System.Drawing.Design.ToolboxItem tool)
            {
                IComponent[] newComponents = tool.CreateComponents(DesignerHost);
            }
        }
    }


}
